#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 5e5 + 10;

int n;
LL a[N];

int main()
{
	// cin >> n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
	{
		scanf("%ld", &a[i]);
		// cin >> a[i];
	}

	sort(a + 1, a + 1 + n);

	for (int i = 1; i <= n; i++)
	{
		printf("%ld ", a[i]);
		// cout << a[i] << " ";
	}
		
	printf("\n");

	for (int i = n; i >= 1; i--)
	{
		printf("%ld ", a[i]);
		// cout << a[i] << " ";
	}

	printf("\n");

	return 0;
}